.panel.panel-default
  .panel-heading
    .panel-title
      .html_title = @html_title
      .pull-right
        = link_to '创建公司', new_sales_firm_path, class: 'btn btn-xs btn-primary', style: "color: white"
  .panel-body
    = search_form_for(@search, builder: SimpleForm::FormBuilder) do |f|
      table.table.table-condensed.table-borderless
        tr
          th style='width:80px' 公司名
          td = f.input_field :name_cont, class: 'form-control'
          th style='width:80px' 字号
          td = f.input_field :short_name_eq, class: 'form-control'
          th style='width:80px' 邮箱
          td = f.input_field :email_cont, class: 'form-control'
        tr
          th 省份城市
          td
            = f.input_field :province_id_eq, as: :select,
                    style: 'width: 100px; display: inline-block',
                    include_blank: true, class: 'form-control relation_province_selector',
                    collection: ::Base::Province.options
            = f.input_field :city_id_eq, as: :select, collection: ::Base::City.options(params[:q][:province_id_eq]),
                    style: 'width: 150px; display: inline-block', class: 'form-control relation_city_selector'
          th 跟进人
          td = f.input_field :leads_user_id_eq, collection: ::Base::User.active.pluck(:username,:id), class: 'form-control'
          th 备注
          td = f.input_field :notes_cont, class: 'form-control'
        tr
          th 电话
          td = f.input_field :phone_cont, class: 'form-control'
          th 评级
          td = f.input_field :rating_eq, collection: ::Sales::Firm::RATING, class: 'form-control'
          th 网址
          td = f.input_field :website_cont, class: 'form-control'
        tr
          td colspan=6
            = reset_button class: 'pull-right'
            = f.submit '搜索', class: 'btn btn-primary pull-right push-10-r'
    = paginate @sales_firms
    table.table.table-condensed
      thead
        tr
          th 公司名
          th 跟进人
          th 省份城市
          th 网址
          th 电话
          th 评级
          th 操作
      tbody
        - @sales_firms.each do |sales_firm|
          tr
            td = link_to truncate(sales_firm.name, length: 40), sales_firm, title: sales_firm.name
            td
              - sales_firm.leads.each do |l|
                p
                  span.badge.badge-info= l.leads_type_text
                  |&nbsp;-&nbsp;
                  = l.user
            td = sales_firm.province_city
            td = sales_firm.website
            td = sales_firm.phone
            td = sales_firm.rating_text
            td
              - if sales_firm.leads.map(&:user_id).include?(current_user.id)
                = link_to_dialog '编辑', edit_sales_firm_path(sales_firm), class: 'btn btn-sm btn-primary push-5-l'
              - else
                = link_to '获取', grab_sales_firm_path(sales_firm), data:{confirm: '确定获取？', remote: true}, class: 'btn btn-sm btn-success push-5-l'
              /= link_to 'Destroy', sales_firm, data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-primary'
